package com.santiao.publics.ui;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.appcompat.widget.AppCompatImageView;

import com.santiao.publics.config.Const;
import com.santiao.publics.util.SharedPreferencesUtil;
import com.santiao.youxiang.R;
import com.santiao.youxiang.SplashActivity;
import com.santiao.publics.base.BaseFragment;


import com.santiao.publics.util.LogUtil;


import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.santiao.publics.ad.ads.AsService;

public class SettingFragment extends BaseFragment implements View.OnClickListener {
    private static volatile SettingFragment instance;

    private LinearLayout tv_user_yxxx, tv_user_yhxx, tv_user_yhfk;
    private AppCompatImageView iv_net_test, iv_signal_enhance, iv_wifi_guard,iv_wifi_net_up;
    private  TextView tv_app_v_text;
    private static Context context;
    private static Activity activity;

    public static FrameLayout mFeedContainer;
    public SettingFragment() {
        // 私有构造函数，防止外部实例化
    }

    public   SettingFragment getInstance(Context contexts,Activity activitys) {
//        if (instance == null) {
//            synchronized (SettingFragment.class) {
//                if (instance == null) {
                    instance = new SettingFragment();
//                }
//            }
//        }
        context = contexts;
        activity = activitys;
        return instance;
    }



    @Nullable
    @Override
    public View onCreateView(@NotNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(getResources().getLayout(R.layout.public_setting_fragment), container, false);
    }

    @Override
    public void onViewCreated(@NotNull View view, @Nullable Bundle savedInstanceState) {

        mFeedContainer =  getView().findViewById(R.id.fl_content_3);
        super.onViewCreated(view, savedInstanceState);
        initView(view);
    }

    @Override
    public void onResume() {
        super.onResume();
        LogUtil.d(Const.TAG,"------SettingFragment---onResume");
//        if (SharedPreferencesUtil.getStatus(SharedPreferencesUtil.IF_AD)) {
//
//            AsService adservice =    new AsService();
//            adservice.initAd("feed", context,getResources().getString(R.string.feed_native_media_id), mFeedContainer  );
//
//
//            adservice.showAd("feed", activity);
////            initAd("full", context,   mFeedContainer);
////////            //插屏
////            showAd("full", activity);
////
////            if(Const.shuangInterstitialFull) {
////                initAd("full2", context,mFeedContainer);
////
////                showAd("full2", activity);
////            }
//            //包检查
//            ApplicationUtil.ifPackageName(getContext().getApplicationContext(), "com.vivo.autotest.screen_record");
//
//        }


    }


    private void initView(View view) {
        tv_user_yxxx = view.findViewById(R.id.tv_user_yxxx);
        tv_user_yhxx = view.findViewById(R.id.tv_user_yhxx);
        tv_user_yhfk = view.findViewById(R.id.tv_user_yhfk);
        tv_app_v_text = view.findViewById(R.id.tv_app_v_text);
//        iv_wifi_net_up = view.findViewById(R.id.iv_wifi_net_up);
//        iv_net_test  = view.findViewById(R.id.iv_net_test);


//        iv_signal_enhance  = view.findViewById(R.id.iv_signal_enhance);
//        iv_wifi_guard  = view.findViewById(R.id.iv_wifi_guard);

        tv_app_v_text.setText("当前版本:"+SplashActivity.versionName);

//        iv_wifi_net_up.setOnClickListener(this);
        tv_user_yxxx.setOnClickListener(this);
        tv_user_yhxx.setOnClickListener(this);
        tv_user_yhfk.setOnClickListener(this);
//        iv_net_test.setOnClickListener(this);
//        iv_signal_enhance.setOnClickListener(this);
//        iv_wifi_guard.setOnClickListener(this);
    }

    @SuppressLint("NonConstantResourceId")
    @Override
    public void onClick(View v) {


                 if (v.getId()== R.id.tv_user_yxxx){
                     WebViewActivity.gotoActivity(getContext(),"隐私协议", "ystk");

                 }
                 else   if (v.getId()== R.id.tv_user_yhxx){
                      WebViewActivity.gotoActivity(getContext(),"用户协议", "yhxy");

                 }
                else   if (v.getId()== R.id.tv_user_yhfk){
                     WebViewActivity.gotoActivity(getContext(), "意见反馈", "yjfk");

                 }
//            //设置
//            case R.id.tv_user_feed_setting:
//                SettingActivity.gotoSettingActivity(getContext());
//                break;

    }



    public static  void adLoad(int position,   String feedId, FrameLayout mFeedContainer , Context context  , Activity activity ){
        if (SharedPreferencesUtil.getStatus(SharedPreferencesUtil.IF_AD)){

            AsService adservice = new AsService();

            if(mFeedContainer!=null) {
                String feedId2 = context.getString(R.string.feed_native_media_id);
                if (feedId != null) {
                    feedId2 = feedId;
                }


                adservice.initAd(
                        "feed",
                        context,
                        feedId2,
                        mFeedContainer
                );

                adservice.showAd("feed", activity);
            }



            //插屏

            adservice.initAd("full", context, activity.getString(R.string.full_media_info_id), null);


            Handler handler = new Handler(Looper.getMainLooper());
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    adservice.showAd("full", activity)  ;
                }
            }, 1500);


            //插屏

            adservice.initAd("full2", context, activity.getString(R.string.full_media_info_2_id), null);


            Handler handler2 = new Handler(Looper.getMainLooper());
            handler2.postDelayed(new Runnable() {
                @Override
                public void run() {
                    adservice.showAd("full2", activity)  ;
                }
            }, 1500);

        }

    }



    public static  void adLoad2(int position,   String feedId, FrameLayout mFeedContainer , Context context  , Activity activity ){
        if (SharedPreferencesUtil.getStatus(SharedPreferencesUtil.IF_AD)){

            AsService adservice = new AsService();




            if(mFeedContainer!=null) {
                String feedId2 = context.getString(R.string.feed_native_media_id);
                if (feedId != null) {
                    feedId2 = feedId;
                }


                adservice.initAd(
                        "feed",
                        context,
                        feedId2,
                        mFeedContainer
                );

                adservice.showAd("feed", activity);
            }
            //插屏

            adservice.initAd("full2", context, activity.getString(R.string.full_media_info_id), null);


//            Handler handler2 = new Handler(Looper.getMainLooper());
//            handler2.postDelayed(new Runnable() {
//                @Override
//                public void run() {
                    adservice.showAd("full2", activity)  ;
//                }
//            }, 1500);




//            //激励视频
//
//            adservice.initAd("reward", context, activity.getString(R.string.reward_media_id), null);
//
//
//            Handler handler = new Handler(Looper.getMainLooper());
//            handler.postDelayed(new Runnable() {
//                @Override
//                public void run() {
//                    adservice.showAd("reward", activity)  ;
//                }
//            }, 1500);


        }

    }
    public static  void adLoad3(int position,   String feedId, FrameLayout mFeedContainer , Context context  , Activity activity ){
        if (SharedPreferencesUtil.getStatus(SharedPreferencesUtil.IF_AD)){

            AsService adservice = new AsService();





//            //插屏
//
//            adservice.initAd("full2", context, activity.getString(R.string.full_media_info_id), null);
//
//
////            Handler handler2 = new Handler(Looper.getMainLooper());
////            handler2.postDelayed(new Runnable() {
////                @Override
////                public void run() {
//                    adservice.showAd("full2", activity)  ;
////                }
////            }, 1500);




            //激励视频

            adservice.initAd("reward", context, activity.getString(R.string.reward_media_id), null);


            Handler handler = new Handler(Looper.getMainLooper());
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    adservice.showAd("reward", activity)  ;
                }
            }, 1500);


        }

    }
}
